# EA SPF DATA Clean AVERAGE LEVEL
rm(list=ls())
(WD <- getwd())
if (!is.null(WD)) setwd(WD)

library(haven)
library(AER)
library(sandwich)
library(lmtest)
library(pracma)
library(stargazer)
library(plm)
library(pracma)
library(DataCombine)
library(jtools)
library(plyr)
library(readxl)

lagpad   = function(x, k) {
  if (!is.vector(x)) 
    stop('x must be a vector')
  if (!is.numeric(x)) 
    stop('x must be numeric')
  if (!is.numeric(k))
    stop('k must be numeric')
  if (1 != length(k))
    stop('k must be a single number')
  c(rep(NA, k), x)[1 : length(x)] 
}

##### EA DATA GDP #############
data    = read_excel("ea_data_avr.xlsx", sheet = "Export")

data$fc_err        = data$fey
data$fc_rev        = data$fry

data               = subset(data, select = c(year,quarter,qdate, fc_err,fc_rev))
data               = data[data$year>="2000",]

save(data, file = "ea_spf_rgdp_avr.rda")
clear()

##### EA DATA CPI #############
data    = read_excel("ea_data_avr.xlsx", sheet = "Export")

data$fc_err        = data$fepi
data$fc_rev        = data$frpi
data$fl            = data$flpi

data               = subset(data, select = c(year,quarter,qdate, fc_err,fl,fc_rev))
data               = data[data$year>="2000",]

save(data, file = "ea_spf_cpi_avr.rda")
clear()
